package com.apartment.own.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnOrdCashPledge;
import com.apartment.own.service.IOwnOrdCashPledgeService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 押金Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/pledge")
public class OwnOrdCashPledgeController extends BaseController
{
    @Autowired
    private IOwnOrdCashPledgeService ownOrdCashPledgeService;

    /**
     * 查询押金列表
     */
    @PreAuthorize("@ss.hasPermi('own:pledge:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnOrdCashPledge ownOrdCashPledge)
    {
        startPage();
        List<OwnOrdCashPledge> list = ownOrdCashPledgeService.selectOwnOrdCashPledgeList(ownOrdCashPledge);
        return getDataTable(list);
    }

    /**
     * 导出押金列表
     */
    @PreAuthorize("@ss.hasPermi('own:pledge:export')")
    @Log(title = "押金", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnOrdCashPledge ownOrdCashPledge)
    {
        List<OwnOrdCashPledge> list = ownOrdCashPledgeService.selectOwnOrdCashPledgeList(ownOrdCashPledge);
        ExcelUtil<OwnOrdCashPledge> util = new ExcelUtil<OwnOrdCashPledge>(OwnOrdCashPledge.class);
        return util.exportExcel(list, "pledge");
    }

    /**
     * 获取押金详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:pledge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownOrdCashPledgeService.selectOwnOrdCashPledgeById(id));
    }

    /**
     * 新增押金
     */
    @PreAuthorize("@ss.hasPermi('own:pledge:add')")
    @Log(title = "押金", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnOrdCashPledge ownOrdCashPledge)
    {
        return toAjax(ownOrdCashPledgeService.insertOwnOrdCashPledge(ownOrdCashPledge));
    }

    /**
     * 修改押金
     */
    @PreAuthorize("@ss.hasPermi('own:pledge:edit')")
    @Log(title = "押金", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnOrdCashPledge ownOrdCashPledge)
    {
        return toAjax(ownOrdCashPledgeService.updateOwnOrdCashPledge(ownOrdCashPledge));
    }

    /**
     * 删除押金
     */
    @PreAuthorize("@ss.hasPermi('own:pledge:remove')")
    @Log(title = "押金", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownOrdCashPledgeService.deleteOwnOrdCashPledgeByIds(ids));
    }
}
